package connect4client.core;

import game.Player;

import java.util.HashMap;
import java.util.Map;

public class PlayerManager {
		
	public PlayerManager() {
		
	}
	
	
	/**
	 * Verifies if the player list contains a given login
	 * 
	 * @param login The player´s login
	 * @return True if the list contains the login
	 */
	public synchronized boolean containsPlayer(Player login) {
		return players.containsKey(login);
	}
	
	
	/**
	 * Adds a player to the player list
	 * 
	 * @param login The player's login
	 * @param player The player object
	 * @return
	 */
	public synchronized Player addPlayer(String login, Player player) {
		return players.put(login, player);
	}

	/**
	 * Removes a player from the player list
	 * 
	 * @param login The player's login
	 */
	public synchronized void removePlayer(String login) {
		players.remove(login);
	}
		
	
	/**
	 * Retrieves a player from the player list
	 * 
	 * @param login
	 * @return The player's login
	 */
	public synchronized Player getPlayerByLogin(String login){
		return players.get(login);
	}
	
	
	public synchronized Map<String,Player> getPlayersMap(){
		return this.players;
	}
	

	private Map<String,Player> players = new HashMap<String,Player>();
}
